from openpyxl import load_workbook


class Do_Excel:
    def __init__(self, filename, sheet_name):
        self.filename = filename
        self.fn = load_workbook(self.filename)  # 打开文件
        self.sheet_name = sheet_name
        self.sheet = self.fn[self.sheet_name]

    # 写入文件
    def write_excel(self, h, l, val):
        self.sheet.cell(h, l).value = val  # 执行结果
        self.fn.save(filename=self.filename)
        self.fn.close()

    # 获取表格的总行数
    def getMaxNumH(self):
        rows = self.sheet.max_row
        return rows

    # 获取表格的总列数
    def getMaxNumL(self):
        columns = self.sheet.max_column
        return columns


if __name__ == '__main__':
    # 写入
    excel = Do_Excel("../report/report.xlsx", 'Sheet1')
    # excel.write_excel(l=1, h=2, val="11")
    # excel.write_excel(l=2, h=2, val="02")
    # excel.write_excel(l=3, h=2, val="03")
    # excel.write_excel(l=4, h=2, val="04")
    # excel.write_excel(l=5, h=2, val="05")
    print(excel.getMaxNumL())
    print(excel.getMaxNumH() + 1)
